<template>
    <base-dialog title="流程干预" size="tiny" v-bind="$attrs" v-on="$listeners" @submit="toSubmit" enterText="修改">
        <el-form ref="myForm" :model="formData" label-width="80px" :rules="rules">
            <el-form-item label="节点" prop="state_id">
                <simple-select  v-model="formData.state_id" :data-list="stateList" placeholder="请选择节点" clearable style="width: 100%" @change="getTypeId"></simple-select>
            </el-form-item>
            <el-form-item label="状态" prop="act_state_id"  v-if="formData.type_id<2">
                <el-select v-model="formData.act_state_id" placeholder="请选择状态" clearable style="width: 100%">
                    <el-option :label="actState.name" :value="actState.id" v-for="(actState,index) in actStateList" :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="人员" prop="participant" v-if="formData.type_id<2&&formData.act_state_id<4">
                <user-all-select  v-model="formData.participant" placeholder="请选择人员" :style="{width: '100%'}" keyname="username"></user-all-select>
            </el-form-item>
        </el-form>
    </base-dialog>
</template>
<script>
    import BaseDialog from "@/components/Common/BaseDialog";
    import api from "@/api/index";
    import SelectTree from "@/components/Common/SelectTree";
    import UserAllSelect from '@/components/Common/UserAllSelect'
    import SimpleSelect from '@/components/Common/SimpleSelect'
    export default {
        name:"InterveneDialog",
        components: { SimpleSelect, UserAllSelect, SelectTree, BaseDialog},
        props:["row"],
        data(){
            return {
                stateList:[],
                deptUserList:[],
                formData:{
                    state_id: "",
                    participant: undefined,
                    act_state_id:1,
                    type_id:0,
                },
                actStateList:[{id:1,name:"进行中"},{id:4,name:"已完成"},{id:5,name:"已关闭"}],//,{id:2,name:"被退回"},{id:3,name:"被撤回"}
                rules: {
                    state_id: [
                        {
                            required: true,
                            message: "请选择节点",
                            trigger: "change"
                        }
                    ],
                    participant: [
                        {
                            required: true,
                            message: "请选择人员",
                            trigger: "change"
                        }
                    ],
                }
            }
        },
        created() {
            this.getState()
        },
        methods:{
            getTypeId(id){
                this.stateList.map(item=>{
                    if(item.id==id){
                        this.formData.type_id = item.type_id
                    }
                })
            },
            getState(){
                api.getSimpleState(this.row.workflow_id).then(res => {
                        this.stateList = res.data;
                        console.log("-----------this.stateList------",this.stateList)
                    }).catch(() => {
                });
            },
            toSubmit(is_draft){
                this.$refs['myForm'].validate(valid => {
                    if (!valid) return
                    api.changTicketsStatus(this.row.id,this.formData).then(res=>{
                        this.msgSuccess(res.msg);
                        this.$emit("reloadList")
                        this.$emit("update:visible",false)
                    })
                })
            },
        }
    }
</script>
